package com.ymatou.auth.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.GetSecurityQuestionBean;
import com.ymatou.auth.parameter.SecurityQuestionAnswer;
import com.ymatou.auth.service.GetSecurityQuestionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallService;
/**
*获取已设置的安全问题
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSecurityQuestion{
	private static GetSecurityQuestionBean getsecurityquestionBean;
	private static GetSecurityQuestionCall getsecurityquestionCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取已设置的安全问题");
	}

	@Before
	public void caseUp() {
		getsecurityquestionBean=new GetSecurityQuestionBean();
		getsecurityquestionCall=new GetSecurityQuestionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsecurityquestionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSecurityQuestion_001() {
		Logger.start(true,"获取已设置的安全问题成功");
		try {
			//使用一个不被使用的userid做安全问题测试
			int userid=2;
			List<SecurityQuestionAnswer> list = AuthCallService.setSecurityQuestion(userid);
			getsecurityquestionBean.setUserId(userid);
			getsecurityquestionCall.setData(getsecurityquestionBean);
			getsecurityquestionCall.callService();			
			Logger.verifyEquals("true", getsecurityquestionCall.getString("Success"), "验证Success");
			Map mResult=(Map) getsecurityquestionCall.getMap().get("Result");
			Logger.verifyEquals(200d, mResult.get("Code"), "验证Code");
			Logger.verifyEquals("success", mResult.get("Msg").toString(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetSecurityQuestion_002() {
		Logger.start(false,"缺少参数UserId,失败");
		try {
			getsecurityquestionCall.setData(getsecurityquestionBean);
			getsecurityquestionCall.callService();			
			Logger.verifyEquals("true", getsecurityquestionCall.getString("Success"), "验证Success");
			Map mResult=(Map) getsecurityquestionCall.getMap().get("Result");
			Logger.verifyEquals(-100d, mResult.get("Code"), "验证Code");
			Logger.verifyEquals("用户ID非法: 0", mResult.get("Msg").toString(), "验证Msg");
			Logger.verifyEquals(0d, mResult.get("NextVerifyDayCount"), "验证NextVerifyDayCount");
			Logger.verifyEquals(0d, mResult.get("UserQuestionId"), "验证UserQuestionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetSecurityQuestion_003() {
		Logger.start(false,"未设置安全问题用户获取已设置的安全问题,失败");
		try {
			getsecurityquestionBean.setUserId(15);
			getsecurityquestionCall.setData(getsecurityquestionBean);
			getsecurityquestionCall.callService();			
			Logger.verifyEquals("true", getsecurityquestionCall.getString("Success"), "验证Success");
			Map mResult=(Map) getsecurityquestionCall.getMap().get("Result");
			Logger.verifyEquals(400d, mResult.get("Code"), "验证Code");
			Logger.verifyEquals("此用户未设置过安全问题", mResult.get("Msg").toString(), "验证Msg");
			Logger.verifyEquals(2d, mResult.get("NextVerifyDayCount"), "验证NextVerifyDayCount");
			Logger.verifyEquals(0d, mResult.get("UserQuestionId"), "验证UserQuestionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}